<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <#include "/pubHeadStyleTree.html">
</head>
<body>

<div style="position: relative;height: 100%;">
    <form class="layui-form">
    <div class="ccpui-trees" >
        <p class="isShowTree colorSwitch">
            <span style="float: left;color: #fff">&nbsp;&nbsp;流程节点分类</span>
            <i layadmin-event="treeFlexible" class="layui-icon layui-icon-prev"></i>
        </p>
        <div style="margin-top: 6px;" >
            <ul class="ccpui-iconTree iconTrees">
                <li><a class="iconfont iconshuaxin- zTree-refresh" title="刷新"></a></li>
                <li><a class="iconfont iconwenjianjia1-copy zTree-triangle-d" title="展开"></a></li>
                <li><a class="iconfont iconfolder1 zTree-triangle-r" title="收起"></a></li>
                <input type="text" style="width: 50%" class="batchZtreeValue">
            </ul>
            <ul id="treeSelectBatch" class="ztree ccpui-listZtree"></ul>
        </div>
    </div>
    <div class="ccpui-coreContent" style="position: absolute;top:10px;right:10px;bottom: 0;left: 250px;padding: 0px 0px 0px 10px;">
        <div class="layui-btn-container">
            <a class="layui-btn layui-btn-sm" lay-event="batchOperator" id="batchOperator">
                <i class="layui-icon layui-icon-file-b"></i>
                <span>批量审批</span>
            </a>
            <a class="layui-btn layui-btn-sm" lay-event="back" id="back">
                <i class="layui-icon layui-icon-return" ></i>
                <span>返回</span>
            </a>
        </div>

        <#if dataList?size <= 0>
            <#if isDataError?string('true','false') == true>
                <div style="text-align: center;margin-top: 10%;">数据异常</div>
            <#else>
                <div style="text-align: center;margin-top: 10%;">暂无数据或需选择左侧批量审批分类</div>
            </#if>
        <#else>
        <div class="ccp_content">
            <table class="layui-table" id="batchApprovalTask" lay-filter="batchApprovalTask" >
                <thead>
                    <tr>
                        <th width="5%">
                            <div class="center-block">
                                <input type="checkbox" id="checkAll" lay-skin="primary" lay-filter="checkAll">
                            </div>
                        </th>
                        <th width="10%">流程名称</th>
                        <#list fieldList as field>
                            <th>${field}</th>
                        </#list>
                    </tr>
                </thead>
                <tbody>
                <#list dataList as data>
                <tr>
                    <td>
                        <input type="checkbox" class="pk" name="id" lay-skin="primary" lay-filter="filter" value="${data['acttaskid']}">
                    </td>
                    <td>

                        <a name="subject" class="subject layui-table-cell" href="javascript:;" taskId="${data['acttaskid']}" title="${data['actsubject']}">${data['actsubject']}</a>
                    </td>
                    <#list fieldNameList as fieldName>
                        <td>${data[fieldName]}</td>
                    </#list>
                </tr>
                </#list>
                </tbody>
            </table>
        </div>
        </#if>
    </form>
    </div>
</div>

<!--// 批量审批意见窗口-->
<div id="batchApprovalOpinion" style="display: none">
    <label class="layui-form-label" style="padding-top: 50px;">审批意见</label>
    <div class="layui-input-inline" style="width: 400px; padding-top: 20px">
        <textarea id="voteContent" name="voteContent" placeholder="请输入内容" class="layui-textarea"></textarea>
    </div>
</div>

<style>
    .iconTrees li {
        display: inline-block;
        margin: 6px 4px;
        cursor: pointer;
    }
    .subject{
        max-width: 320px;
        display: inline-block;
        cursor: pointer;
        color: blue;
        text-decoration: underline;
    }
    .subject:hover{
        color: blue;
    }
    #batchApprovalTask th{
        padding: 9px 15px;
    }
    #batchApprovalTask th,#batchApprovalTask td{
        text-align: center;
    }
    .ccp_content{
        position: absolute;
        left: 0;
        width: 100%;
        overflow: auto;
    }
</style>

<script>

    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','layer', 'form', 'setter'], function () {
        var layer = layui.layer;
        var form = layui.form;
        var $ = layui.$;
        var setter = layui.setter;

        batchZtree();
        form.render(); //更新全部
        function batchZtree() {
            var setting = {
                view: {
                    showLine: false,
                    nameIsHTML: true, //允许name支持html
                    selectedMulti: false
                },
                edit: {
                    enable: false,
                    editNameSelectAll: false
                },
                data: {
                    simpleData: {
                        enable: true,
                        pIdKey: "pid"
                    }
                },
                callback: {
                    onClick: onClickType
                }
            };
            $.ajax({
                url: serverPath.workflowPath + "/workflow/bpmBatchApproval/tree",
                type: "post",
                dataType: 'json',
                async: false,
                success: function (result) {
                    if (result.code === 0) {
                        var data = result.data;
                        for(var i=0; i<data.length; i++){
                            var node = data[i];
                            node.open = true;
                        }
                        $.fn.zTree.init($('#treeSelectBatch'), setting, data);
                        component.fuzzySearch('treeSelectBatch', '.batchZtreeValue', null, true); //初始化模糊搜索方法
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert("暂无数据，请稍后操作！" + XMLHttpRequest.status);
                }
            });
        }

        function onClickType(event, treeId, treeNode) {
            if (treeNode.pid === undefined || treeNode.pid== null || treeNode.pid === '') {
                return;
            }
            location.href = serverPath.workflowPath + "/workflow/bpmBatchApproval/view/listBatchTasks?batchId=" + treeNode.batchId;
        }

        //展开
        $(".iconTrees .zTree-triangle-d").click(function () {
            $.fn.zTree.getZTreeObj("treeSelectBatch").expandAll(true);
        });
        //收起
        $(".iconTrees .zTree-triangle-r").click(function () {
            $.fn.zTree.getZTreeObj("treeSelectBatch").expandAll(false);
        });
        //刷新
        $(".iconTrees .zTree-refresh").click(function () {
            batchZtree();
        });

        $("#back").click(function () {
            location.href = serverPath.workflowPath + "/workflow/task/view/pendingMatters";
        });

        // 任务详情
        $(".subject").click(function () {
            var taskId = $(this).attr("taskId");
            var title = $(this).attr("title");
            var isNeedReload = true;
            parent.layer.open({
                type: 2,
                title: "流程任务-["+title+"]执行",
                area: ['1300px', '680px'],
                content: serverPath.workflowPath + setter.workflowLinkPath +"task/view/toStart?taskId=" + taskId,
                cancel: function () {
                    isNeedReload = false;
                },
                end:function () {
                    if (isNeedReload) {
                        location.href = serverPath.workflowPath + "/workflow/bpmBatchApproval/view/listBatchTasks";
                    }
                }
            });
        });
        form.on('checkbox(checkAll)', function(data){
            var child = $("tbody input[type='checkbox']");
            child.each(function (index, item) {
                item.checked = data.elem.checked;
            });
            form.render('checkbox');
        });
        form.on('checkbox(filter)', function(data){
            var item = $(".pk");
            for (var i = 0; i < item.length; i++) {
                if (item[i].checked == false) {
                    $("#checkAll").prop("checked", false);
                    form.render('checkbox');
                    break;
                }
            }
            //如果都勾选了  勾上全选
            var  all=item.length;
            for (var i = 0; i < item.length; i++) {
                if (item[i].checked == true) {
                    all--;
                }
            }
            if(all==0){
                $("#checkAll").prop("checked", true);
                form.render('checkbox');
            }
        });

        // 批量审批
        $("#batchOperator").click(function () {
            var aryId = $("input[type='checkbox'][disabled!='disabled'][class='pk']:checked");
            var len=aryId.length;
            if(len==0){
                layer.alert("请选择记录！","提示信息");
                return;
            }
            var taskIds=new Array();
            $("input[name='id']:checked").each(function(){
                taskIds.push($(this).val());
            });
            var ids=taskIds.join(",");

            var opinionDialogIndex = layer.open({
                type: 1,
                title: "审批意见",
                area: ['520px','300px'],
                content: $('#batchApprovalOpinion'),
                skin: 'btn-class',
                btn: ['审批','取消'],
                btnAlign: 'c',
                yes: function(index,layero){
                    var data = {taskIds: ids, opinion: $("#voteContent").val()};
                    layer.confirm("'批量批准,只能批准“同意”,<br/>是否确认批量审批？'", function (index) {
                        var url = serverPath.workflowPath + "/workflow/bpmBatchApproval/batchComplete";
                        $.post(url,data,function (result) {
                            if (result.code === 0) {
                                layer.alert(result.msg,function(index){
                                    layer.close(index);
                                    layer.close(opinionDialogIndex);
                                    location.href = serverPath.workflowPath + "/workflow/bpmBatchApproval/view/listBatchTasks";
                                });
                            } else {
                                layer.alert(result.msg);
                            }
                        }, "json")
                    })

                }
            });

        });
        $(".ccp_content").css("height",$(".ccpui-coreContent").outerHeight()-$(".layui-btn-container").outerHeight()+'px').css("top",$(".layui-btn-container").outerHeight()+'px')
        window.onresize=function(){
            $(".ccp_content").css("height",$(".ccpui-coreContent").outerHeight()-$(".layui-btn-container").outerHeight()+'px').css("top",$(".layui-btn-container").outerHeight()+'px')
        }


    });
</script>
</body>
</html>
